package net.imwork.amorgemini.core.config;

import org.activiti.spring.SpringAsyncExecutor;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.AbstractProcessEngineAutoConfiguration;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.PlatformTransactionManager;

import javax.sql.DataSource;
import java.io.IOException;

/**
 * activiti配置文件
 * AbstractProcessEngineAutoConfiguration在activiti-spring-boot-starter-basic下
 */
@Configuration
public class ActivitiConfig extends AbstractProcessEngineAutoConfiguration {
    static final String NAME = "primary";

    //注入数据源和事务管理器
    @Bean
    public SpringProcessEngineConfiguration springProcessEngineConfiguration(
            @Qualifier(NAME + "DataSource") DataSource dataSource, // 注入数据源
            @Qualifier(NAME + "TransactionManager") PlatformTransactionManager transactionManager, // 注入事务管理类
            SpringAsyncExecutor springAsyncExecutor) throws IOException {
        return this.baseSpringProcessEngineConfiguration(dataSource, transactionManager, springAsyncExecutor);
    }
}